package cn.git.agent.interceptor;

import cn.git.agent.enhance.EnhancedInstance;
import cn.git.agent.enhance.InstanceMethodAroundInterceptor;

import java.lang.reflect.Method;

/**
 * @description: spirngMVC拦截器
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2024-12-24
 */
public class SpringMVCInterceptor implements InstanceMethodAroundInterceptor {
    /**
     * 前置方法
     *
     * @param objectInstance
     * @param method
     * @param allArguments
     * @param paramTypes
     */
    @Override
    public void beforeMethod(EnhancedInstance objectInstance, Method method, Object[] allArguments, Class<?>[] paramTypes) {
        System.out.println("SpringMVCInterceptor 具体方法 beforeMethod 执行开始");
    }

    /**
     * 后置方法,最終通知，不管原方法是否執行都會執行，finally裡面邏輯
     *
     * @param objectInstance
     * @param method
     * @param allArguments
     * @param paramTypes
     * @param ret
     */
    @Override
    public void afterMethod(EnhancedInstance objectInstance, Method method, Object[] allArguments, Class<?>[] paramTypes, Object ret) {
        System.out.println("SpringMVCInterceptor 具体方法 afterMethod 执行开始");
    }

    /**
     * 异常方法
     *
     * @param objectInstance
     * @param method
     * @param allArguments
     * @param paramTypes
     * @param t
     */
    @Override
    public void handleMethodException(EnhancedInstance objectInstance, Method method, Object[] allArguments, Class<?>[] paramTypes, Throwable t) {
        System.out.println("SpringMVCInterceptor 具体方法 handleMethodException 执行开始 error: " + t.getMessage());
    }
}
